home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / peacoc / sampldll.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-19  |  10.4 KB  |  333 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Color By Name"
  4.    ClientHeight    =   4425
  5.    ClientLeft      =   1440
  6.    ClientTop       =   1980
  7.    ClientWidth     =   5655
  8.    Height          =   5115
  9.    Icon            =   SAMPLDLL.FRX:0000
  10.    Left            =   1380
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4425
  13.    ScaleWidth      =   5655
  14.    Top             =   1350
  15.    Width           =   5775
  16.    Begin ListBox List2 
  17.       Height          =   3930
  18.       Left            =   2955
  19.       TabIndex        =   1
  20.       Top             =   300
  21.       Width           =   2520
  22.    End
  23.    Begin ListBox List1 
  24.       BackColor       =   &H00FFFFFF&
  25.       Height          =   3930
  26.       Left            =   165
  27.       TabIndex        =   0
  28.       Top             =   285
  29.       Width           =   2520
  30.    End
  31.    Begin CommonDialog CMDialog 
  32.       Left            =   2535
  33.       Top             =   3525
  34.    End
  35.    Begin Label Label2 
  36.       Caption         =   "User Defined Colors"
  37.       Height          =   255
  38.       Left            =   2955
  39.       TabIndex        =   3
  40.       Top             =   45
  41.       Width           =   2085
  42.    End
  43.    Begin Label Label1 
  44.       Caption         =   "Predefined Colors"
  45.       Height          =   255
  46.       Left            =   210
  47.       TabIndex        =   2
  48.       Top             =   45
  49.       Width           =   2085
  50.    End
  51.    Begin Menu M_FILE 
  52.       Caption         =   "&File"
  53.       Begin Menu M_EXIT 
  54.          Caption         =   "E&xit"
  55.       End
  56.    End
  57.    Begin Menu M_EDIT 
  58.       Caption         =   "&Edit"
  59.       Begin Menu M_ADD_COLOR 
  60.          Caption         =   "&Add Color"
  61.       End
  62.       Begin Menu M_CHANGE 
  63.          Caption         =   "&Change Color"
  64.       End
  65.       Begin Menu M_DELETE 
  66.          Caption         =   "&Delete Color"
  67.       End
  68.    End
  69.    Begin Menu M_VIEW 
  70.       Caption         =   "&View"
  71.       Begin Menu M_VIEW_COLOR 
  72.          Caption         =   "&Color Name"
  73.          Begin Menu M_NAME_USER 
  74.             Caption         =   "&User Defined"
  75.          End
  76.          Begin Menu M_NAME_PRE 
  77.             Caption         =   "&Predefined"
  78.          End
  79.       End
  80.       Begin Menu M_DETAIL 
  81.          Caption         =   "Color &Detail"
  82.          Begin Menu M_COLOR_USER 
  83.             Caption         =   "&User Defined"
  84.          End
  85.          Begin Menu M_COLOR_PRE 
  86.             Caption         =   "&Predefined"
  87.          End
  88.       End
  89.    End
  90. Option Explicit
  91. Sub Form_Load ()
  92.   Dim winDir As String
  93.   Dim infile As Integer
  94.   Dim inline As String
  95.   Dim pos As Integer
  96.   Dim listString As String
  97.   On Error GoTo ErrorEditRgb
  98.   ' get a list of the colors supported
  99.   listString = Space$(10 * 1024) ' 10 K
  100.   cbnGetColorList listString, 10 * 1024
  101.   ' find the double 0 at the end
  102.   pos = InStr(listString, Chr$(0) + Chr$(0))
  103.   ' leave one of the 0s for the end of the last string
  104.   listString = Left$(listString, pos)
  105.   pos = InStr(listString, Chr$(0))
  106.   While pos <> 0
  107.     List1.AddItem Mid$(listString, 1, pos - 1)
  108.     listString = Mid$(listString, pos + 1, Len(listString))
  109.     pos = InStr(listString, Chr$(0))
  110.   Wend
  111.   listString = Space$(10 * 1024)
  112.   cbnGetUserColorList listString, 10 * 1024
  113.   ' find the double 0 at the end
  114.   pos = InStr(listString, Chr$(0) + Chr$(0))
  115.   ' leave one of the 0s for the end of the last string
  116.   listString = Left$(listString, pos)
  117.   pos = InStr(listString, Chr$(0))
  118.   While pos <> 0
  119.     List2.AddItem Mid$(listString, 1, pos - 1)
  120.     listString = Mid$(listString, pos + 1, Len(listString))
  121.     pos = InStr(listString, Chr$(0))
  122.   Wend
  123.   ' point the lists to the right place
  124.   If List1.ListCount <> 0 Then
  125.     List1.ListIndex = 0
  126.     List1_DblClick
  127.   End If
  128.   If List2.ListCount <> 0 Then
  129.     List2.ListIndex = 0
  130.     List2_DblClick
  131.   End If
  132. ErrorEditRgb:
  133.   Exit Sub
  134. End Sub
  135. Sub List1_Click ()
  136.   List1_DblClick
  137. End Sub
  138. Sub List1_DblClick ()
  139.   Dim colorName As String
  140.   Dim Color As Long
  141.   colorName = List1.List(List1.ListIndex)
  142.   If cbnColorExists(colorName) = CBN_NOT_EXISTS Then
  143.     MsgBox "Error: Color name " + colorName + " does not exist", 48, "Color Name Error"
  144.     Exit Sub
  145.   End If
  146.   Color = cbnGetColor(colorName, CLng(List1.BackColor))
  147.   List1.BackColor = Color
  148. End Sub
  149. Sub List2_Click ()
  150.   List2_DblClick
  151. End Sub
  152. Sub List2_DblClick ()
  153.   Dim colorName As String
  154.   Dim Color As Long
  155.   colorName = List2.List(List2.ListIndex)
  156.   If cbnColorExists(colorName) = CBN_NOT_EXISTS Then
  157.     MsgBox "Error: Color name " + colorName + " does not exist", 48, "Color Name Error"
  158.     Exit Sub
  159.   End If
  160.   Color = cbnGetColor(colorName, CLng(List2.BackColor))
  161.   List2.BackColor = Color
  162. End Sub
  163. Sub M_ADD_COLOR_Click ()
  164.   Dim colorName As String
  165.   On Error GoTo ErrorHandler
  166.   colorName = InputBox("Enter New Color Name:", "Color Name")
  167.   If colorName = "" Then
  168.     Exit Sub
  169.   End If
  170.    If cbnColorExists(colorName) = CBN_EXISTS And cbnUserColorExists(colorName) = CBN_NOT_EXISTS Then
  171.     MsgBox "Error: Color " + colorName + " already exists", 48, "Color Name Error"
  172.     Exit Sub
  173.   End If
  174.    If cbnUserColorExists(colorName) = CBN_EXISTS Then
  175.     MsgBox "Error: User Color " + colorName + " already exists", 48, "Color Name Error"
  176.     Exit Sub
  177.   End If
  178.   CMDialog.CancelError = True
  179.   CMDialog.Flags = &H2&
  180.   CMDialog.Action = 3
  181.   cbnAddUserColor colorName, CLng(CMDialog.Color)
  182.   List2.BackColor = CMDialog.Color
  183.   List2.AddItem colorName
  184.   List2.ListIndex = List2.NewIndex
  185. ErrorHandler:
  186.   ' user pressed the cancel button
  187.   Exit Sub
  188. End Sub
  189. Sub M_CHANGE_Click ()
  190.   Dim colorName As String
  191.   Dim Color As Long
  192.   Dim cnt As Integer
  193.   On Error GoTo ErrorHandler2
  194.   colorName = InputBox("Enter Color Name To Change:", "Color Name", List2.List(List2.ListIndex))
  195.   If colorName = "" Then
  196.     Exit Sub
  197.   End If
  198.   If cbnColorExists(colorName) = CBN_EXISTS And cbnUserColorExists(colorName) = CBN_NOT_EXISTS Then
  199.     MsgBox "Error: " + colorName + " is predefined - can only change user colors", 48, "Color Name Error"
  200.     Exit Sub
  201.   End If
  202.   If cbnUserColorExists(colorName) = CBN_NOT_EXISTS Then
  203.     MsgBox "Error: User Color " + colorName + " does not exist", 48, "Color Name Error"
  204.     Exit Sub
  205.   End If
  206.   Color = cbnGetColor(colorName, CLng(List2.BackColor))
  207.   CMDialog.Color = Color
  208.   CMDialog.CancelError = True
  209.   CMDialog.Flags = &H2& Or &H1&
  210.   CMDialog.Action = 3
  211.   cbnAddUserColor colorName, CLng(CMDialog.Color)
  212.   List2.BackColor = CMDialog.Color
  213.   ' find colorName in the list and set the index to it
  214.   For cnt = 0 To List2.ListCount
  215.     If List2.List(cnt) = colorName Then
  216.       List2.ListIndex = cnt
  217.       Exit For
  218.     End If
  219.   Next
  220. ' Error handling here please
  221. ErrorHandler2:
  222.   ' user pressed the cancel button
  223.   Exit Sub
  224. End Sub
  225. Sub M_COLOR_PRE_Click ()
  226.   Dim colorName As String
  227.   Dim Color As Long
  228.   On Error GoTo ErrorHandlerColorPre
  229.   colorName = InputBox("Enter Color Name To View:", "Color Name", List1.List(List1.ListIndex))
  230.   If colorName = "" Then
  231.     Exit Sub
  232.   End If
  233.   If cbnColorExists(colorName) = CBN_NOT_EXISTS Then
  234.     MsgBox "Error: Color " + colorName + " does not exist", 48, "Color Name Error"
  235.     Exit Sub
  236.   End If
  237.   Color = cbnGetColor(colorName, CLng(List1.BackColor))
  238.   List1.BackColor = Color
  239.   CMDialog.Color = Color
  240.   CMDialog.CancelError = True
  241.   CMDialog.Flags = &H2& Or &H1&
  242.   CMDialog.Action = 3
  243. ErrorHandlerColorPre:
  244.   ' user pressed the cancel button
  245.   Exit Sub
  246. End Sub
  247. Sub M_COLOR_USER_Click ()
  248.   Dim colorName As String
  249.   Dim Color As Long
  250.   On Error GoTo ErrorHandlerColorUser
  251.   colorName = InputBox("Enter Color Name To View:", "Color Name", List2.List(List2.ListIndex))
  252.   If colorName = "" Then
  253.     Exit Sub
  254.   End If
  255.   If cbnColorExists(colorName) = CBN_NOT_EXISTS Then
  256.     MsgBox "Error: Color " + colorName + " does not exist", 48, "Color Name Error"
  257.     Exit Sub
  258.   End If
  259.   Color = cbnGetColor(colorName, CLng(List2.BackColor))
  260.   List2.BackColor = Color
  261.   CMDialog.Color = Color
  262.   CMDialog.CancelError = True
  263.   CMDialog.Flags = &H2& Or &H1&
  264.   CMDialog.Action = 3
  265. ErrorHandlerColorUser:
  266.   ' user pressed the cancel button
  267.   Exit Sub
  268. End Sub
  269. Sub M_DELETE_Click ()
  270.   Dim colorName As String
  271.   Dim Color As Long
  272.   Dim cnt As Integer
  273.   On Error GoTo ErrorHandlerDelete
  274.   colorName = InputBox("Enter Color Name To Delete:", "Color Name", List2.List(List2.ListIndex))
  275.   If colorName = "" Then
  276.     Exit Sub
  277.   End If
  278.   If cbnColorExists(colorName) = CBN_EXISTS And cbnUserColorExists(colorName) = CBN_NOT_EXISTS Then
  279.     MsgBox "Error: " + colorName + " is predefined - can only delete user colors", 48, "Color Name Error"
  280.     Exit Sub
  281.   End If
  282.   If cbnUserColorExists(colorName) = CBN_NOT_EXISTS Then
  283.     MsgBox "Error: User Color " + colorName + " does not exist", 48, "Color Name Error"
  284.     Exit Sub
  285.   End If
  286.   cbnDeleteUserColor colorName
  287.   ' find colorname in the user defined list and
  288.   ' blow it away
  289.   For cnt = 0 To List2.ListCount
  290.     If List2.List(cnt) = colorName Then
  291.       List2.RemoveItem cnt
  292.       Exit For
  293.     End If
  294.   Next
  295.   List2.ListIndex = 0
  296.   List2_Click
  297. ' Error handling here please
  298. ErrorHandlerDelete:
  299.   ' user pressed the cancel button
  300.   Exit Sub
  301. End Sub
  302. Sub M_EXIT_Click ()
  303.   End
  304. End Sub
  305. Sub M_NAME_PRE_Click ()
  306.   Dim colorName As String
  307.   Dim Color As Long
  308.   colorName = InputBox("Enter Color Name to View:", "View Color By Name", List1.List(List1.ListIndex))
  309.   If colorName = "" Then
  310.     Exit Sub
  311.   End If
  312.   If cbnColorExists(colorName) = CBN_NOT_EXISTS Then
  313.     MsgBox "Error: Color name " + colorName + " does not exist", 48, "Color Name Error"
  314.     Exit Sub
  315.   End If
  316.   Color = cbnGetColor(colorName, CLng(List1.BackColor))
  317.   List1.BackColor = Color
  318. End Sub
  319. Sub M_NAME_USER_Click ()
  320.   Dim colorName As String
  321.   Dim Color As Long
  322.   colorName = InputBox("Enter Color Name to View:", "View Color By Name", List2.List(List2.ListIndex))
  323.   If colorName = "" Then
  324.     Exit Sub
  325.   End If
  326.   If cbnColorExists(colorName) = CBN_NOT_EXISTS Then
  327.     MsgBox "Error: Color name " + colorName + " does not exist", 48, "Color Name Error"
  328.     Exit Sub
  329.   End If
  330.   Color = cbnGetColor(colorName, CLng(List2.BackColor))
  331.   List2.BackColor = Color
  332. End Sub
  333.